<?php
namespace app\beautiful\model\mall;
use app\common\model\CommonModel;

class StoreGoodsModel extends CommonModel{
    protected  $name = 'beautiful_store_goods';
    protected  $pk   = 'store_goods_id';
    protected $type=[
        'gift_giving'=>'array'
    ];

    public function goods()
    {
        return $this->hasOne(GoodsModel::class,'goods_id','goods_id');
    }

    public function getGiftTotalPriceAttr($value,$data)
    {
        $price=0;
        $gift_giving=json_decode($data['gift_giving'],true);
        if(!empty($gift_giving)){
            foreach ($gift_giving as $k =>$v){
                $price=$price+round(($v['price']*100*$v['num'])/100,2);
            }
        }
        return $price;
    }

}
